package com.cloud.sample.consumer.core.http;

import java.util.List;

/**
 * @author gjy
 * @since 2021/7/5 0005
 */
public class ApiPagerResponse<T> extends ApiListResponse<T> {

    private int page;

    private int limit;

    private int total;

    public ApiPagerResponse(String message) {
        super(message);
    }

    public ApiPagerResponse(Integer code, String message) {
        super(code, message);
    }

    public ApiPagerResponse(Integer code, String message, Integer errorCode) {
        super(code, message, errorCode);
    }

    public ApiPagerResponse(Integer code, String message, Integer errorCode, List<T> rows) {
        super(code, message, errorCode);
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public static class Builder {
        public static <T> ApiPagerResponse<T> ok() {
            return ok(null);
        }

        public static <T> ApiPagerResponse<T> ok(List<T> data) {
            return ok("success", data);
        }

        public static <T> ApiPagerResponse<T> ok(String message, List<T> data) {
            return build(200, message, 200, data);
        }


        public static <T> ApiPagerResponse<T> fail() {
            return fail("error");
        }

        public static <T> ApiPagerResponse<T> fail(String message) {
            return fail(400, message);
        }

        public static <T> ApiPagerResponse<T> fail(Integer errorCode, String message) {
            return build(400, message, errorCode, null);
        }

        private static <T> ApiPagerResponse<T> build(Integer code, String message, Integer errorCode, List<T> data) {

            return new ApiPagerResponse<T>(code, message, errorCode, data);
        }
    }
}
